package server.utility;

import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.Serializable;

public class Point2d implements Serializable{
	private int x,y;
	
	public Point2d(){
		x=y=0;
	}
	
	public Point2d(int x, int y){
		this.x=x;
		this.y=y;
	}

	public int getX() {
		return x;
	}

	public void setX(int x) {
		this.x = x;
	}

	public int getY() {
		return y;
	}

	public void setY(int y) {
		this.y = y;
	}

	public void plus(Point2d vect) {
		x+=vect.x;
		y+=vect.y;
	}
	
	public String toString(){
		return x+","+y;
	}
	
	public static Point2d fromString(String s){
		Point2d ret=new Point2d();
		String[] split=s.split(",");
		try{
			ret.x=Integer.parseInt(split[0]);
			ret.y=Integer.parseInt(split[1]);
		}catch(Exception ex){}
		
		return ret;
	}
	
	private void readObject(ObjectInputStream in) throws IOException,
	ClassNotFoundException {
		int ver=in.readInt();
		
		switch(ver){
		
			case 1:{
				x = in.readInt();
				y = in.readInt();				
			}
		}
	}
	
	private void writeObject(ObjectOutputStream out) throws IOException {
		out.writeInt(1); //version
		
		out.writeInt(x);
		out.writeInt(y);
		
	}

	public Point2d copy() {
		return new Point2d(this.x, this.y);
	}
	
}